const app = getApp()
const request = require('../../../utils/https.js')
import util from '../../../utils/util.js';
var userId;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navList: ['全部', '待付款', '待发货', '待收货', '售后服务'],
    active: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
    userId = wx.getStorageSync('userId');
    wx.request({
      url: getApp().Api_url + 'faq/all',
      method: 'GET',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      data: {},
      success: (res) => {
        if (res.data.code == 200) {
          console.log('常见问题==>', res.data.data)
          that.setData({
            navList: res.data.data
          })
          that.problem(res.data.data[0].typeValue)
        }
      }
    })
  },

  onClick(event) {
    const that = this;
    let navIndex = event.detail.index;
    let navList = that.data.navList;
    console.log('问题===>', navList[navIndex].typeValue)
    let typeValue = navList[navIndex].typeValue;
    that.problem(typeValue);
    that.setData({
      active: navIndex
    })
  },
  problem(typeValue) {
    const that = this;
    wx.request({
      url: getApp().Api_url + 'faq/single',
      method: 'GET',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      data: {
        type: typeValue,
        pageNum: 1,
        pageSize: 100
      },
      success: (res) => {
        if (res.data.code == 200) {
          console.log('常见问题==>', res.data.data)
          that.setData({
            proList: res.data.data
          })
        }
      }
    })
  },

  goDePro(e) {
    const that = this;
    let title = encodeURIComponent(e.currentTarget.dataset.title);
    let content =  encodeURIComponent(e.currentTarget.dataset.content);
    console.log('content==>', content)
    wx.navigateTo({
      url: '/packageB/pages/detpro/detpro?title=' + title + '&content=' + content,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})